import md5 from 'crypto-js/md5'
import { enc } from 'crypto-js'

// MD5加密（带盐）
export function encryptPassword(password: string, salt: string): string {
  return md5(password + salt).toString(enc.Hex)
}

// 获取服务器盐值
export async function getSalt(): Promise<string> {
  try {
    const response = await fetch('/api/auth/salt')
    if (!response.ok) {
      throw new Error('获取盐值失败')
    }
    const data = await response.json()
    return data.salt
  } catch (error) {
    console.error('获取盐值错误:', error)
    throw error
  }
} 